 const CHARTS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
 function encode(str) {
   let buf = Buffer.from(str);
   let result = '';
   let suffix = '';
   for (let b of buf) {
     result += b.toString(2).padStart(8, 0)
   }
   if ((result.length % 6) === 4) { // 一个字节的情况
     suffix = '=';
     result += '00';
   }
   if ((result.length % 6) === 2) { // 剩余两个字节的情况
     suffix = '==';
     result += '0000';
   }
   return result.match(/(\d{6})/g).map(val => parseInt(val, 2)).map(val => CHARTS[val]).join('') + suffix
 }

function decode(str) {
      var result = '';
      for (let b of str) {
        if(b==='=') break;
        result += (CHARTS.indexOf(b)).toString(2).padStart(6, 0)
      }    
      var list =  result.match(/(\d{8})/g).map((number)=>{
        return parseInt(number, 2)
      })
      return Buffer.from(list).toString('utf8')
 }
 var ss = encode('朱昆m');
 console.log(ss)
 console.log(decode(ss))